import { reqCategorys } from './service'
import {message} from "antd";


export default {
  namespace: 'categorys',
  state: {

  },
  effects: {
    // 获取分类列表
    *fetchCategorys({ payload, callback }, { call }){
      try {
        const { status, data } = yield call(reqCategorys, {
          payload: {
            params:{
              ...payload
            }
          }
        })
        if (status === 0) {
          // 读取分类列表的数据(可能是一级/二级分类列表)
          const categorys = data
          if (callback) callback(categorys)
        }else {
          message.error('获取分类列表失败')
        }
      }catch (e) {
        console.log(e);
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload
      };
    },
  }
}
